package com.example.ormsqlsplicingframe1.utlis;

import com.example.ormsqlsplicingframe1.orm.registry.*;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

//拓张变量类型 让json工具类也可以使用
public class ImportTypeUtils {

    private static Map<Class, Registry> map = new HashMap<>();

    private static  ImportTypeUtils importTypeUtils;

    public  Object getValue(Field field,Object value) {

        Registry registry = map.get(field.getType());

        if (registry != null){
            return registry.decode(value, field);
        }
        return null;
    }

    public Registry get(Class<?> a ){
        return map.get(a);
    }

    public ImportTypeUtils  put(Class<?> aclss,Registry registry){
        map.put(aclss,registry);
        return this;
    }

    public synchronized static  ImportTypeUtils newInstance() {

        if (importTypeUtils == null ){
            importTypeUtils = new ImportTypeUtils();
        }

        return importTypeUtils ;
    }

}
